//------------------------------------------------------------------------------
// @description 管理员端-突出工作-进行中-详情
//------------------------------------------------------------------------------
<script setup name="OutstandingWorkProceedDetail">
//------------------------------------------------------------------------------
// 模块引入
//------------------------------------------------------------------------------
import { ref } from 'vue';
import { useRouter } from 'vue-router';

import { ElTable, ElTableColumn, ElPagination, ElSelect, ElOption,ElMessage } from 'element-plus';
import { Search } from '@element-plus/icons-vue';

import service from '@/utils/request';

//------------------------------------------------------------------------------
// 数据存储
//------------------------------------------------------------------------------
const router = useRouter();
const routerQuery = router.currentRoute.value.query;
const tableData = ref([])
const pageNum = ref(1); // 当前页码
const pageSize = ref(5); // 每页显示的条数
const totalSize = ref(0); // 总条数

const searchValue = ref(''); // 搜索框的值
const searchRef = ref(null);// 右侧搜索框元素

const score = ref('');//分数

//------------------------------------------------------------------------------
// 数据处理方法
//------------------------------------------------------------------------------

//获取表格数据
const fixedTableData = (data) => {
    if (data.length === 0) return [];
    return data.map(item => {
        return {
            name: item.studentName,
            id: item.studentId,
            major: item.major,
            grade: item.studentGrade,
            class: item.studentClass,
            taskState: item.state,
            score: item.score,
            operation: '详情',
        }
    })
}
const getTableData = (searchKey) => {
    service({
        method: "get",
        url: "/admin/classworklist",
        headers: {
            Authorization: localStorage.getItem('token'),
        },
        params: {
            TeacherId: routerQuery.teacherId,
            StudentName: searchKey,
            ProminentWorkId: routerQuery.taskId,
            pageNum: pageNum.value,
            pageSize: pageSize.value,
        }
    }).then((res) => {
        tableData.value = fixedTableData(res.data.list[0].classStudentWorkResults);
        totalSize.value = res.data.total
    })
}
getTableData("");

//点击保存
const saveClick = () => {
    service({
        method: "post",
        url: "/admin/teacherprominentworkscore",
        headers: {
            Authorization: localStorage.getItem('token'),
        },
        params: {
            teacherId: Number(routerQuery.teacherId),
            ProminentWorkId: Number(routerQuery.taskId),
            score: Number(score.value) || 0,
        }
    }).then((res) => {
        if (res.data.message === "请求正常") {
            ElMessage({
                message: "保存成功",
                type: "success",
            });
        } else {
            ElMessage({
                message: "保存失败" + res.data.message,
                type: "error",
            })
        }
    })
}

// 搜索框聚焦和失焦事件
const searchFocus = () => {
    searchRef.value.classList.add('searchActive');
};
const searchBlur = () => {
    if (searchValue.value === '') {
        searchRef.value.classList.remove('searchActive');
    }
}
const searchChange = () => {
    getTableData(searchValue.value);
}

//点击班级详情
const operationClick = (row, column) => {
    if(column.property !== 'operation'){
        return;
    }
    router.push({
        path: '/administrator/outstandingWork/proceed/detail/mark',
        query: { ...row,...routerQuery }
    })
}

//底部分页相关
const handleSizeChange = (val) => {
    pageSize.value = val
    getTableData(searchValue.value);
}
</script>

<template>
    <div class="bseWorkProceedDetail">
        <div class="header">
            <span @click="router.push('/administrator/outstandingWork')">进行中-突出工作</span>
            <span>/班级填报情况</span>
        </div>
        <!-- 表格 -->
        <div class="layout">
            <div class="info">
                <div class="infoHeader">{{ routerQuery.taskName }}</div>
                <div class="infoContent">
                    <div class="item">
                        <div class="title">导师姓名</div>
                        <div>{{ routerQuery.name }}</div>
                    </div>
                    <div class="item">
                        <div class="title">工号</div>
                        <div>{{ routerQuery.teacherId }}</div>
                    </div>
                    <div class="item">
                        <div class="title">任务名称</div>
                        <div>{{ routerQuery.taskName }}</div>
                    </div>
                    <div class="score">
                        <div class="title">分数</div>
                        <div class="input">
                            <input type="text" placeholder="请输入" v-model="score">
                        </div>
                        <div class="save" @click="saveClick">保存</div>
                    </div>
                </div>
            </div>
            <div class="dataTable">
                <div class="content">
                    <!-- 搜索框头部 -->
                    <div class="tableHeader">
                        <div class="left">
                            <span>班级填报情况</span>
                        </div>
                        <div class="right" >
                            <div class="search" ref="searchRef">
                                <input 
                                v-model="searchValue" 
                                type="text" 
                                placeholder="搜索" 
                                @focus="searchFocus" 
                                @blur="searchBlur"
                                @keyup.enter="searchChange"
                                />
                                <el-icon class="icon"><Search /></el-icon>
                            </div>
                        </div>
                    </div>
                    <!-- 数据表格 -->
                    <div class="tableContent">
                        <el-table
                        :data="tableData"
                        :style="{width: '100%'}"
                        height="100%"
                        show-overflow-tooltip
                        empty-text="暂无数据"
                        :header-cell-style="{color: '#000', background: '#f2f3f5'}"
                        @cell-click="operationClick"
                        >
                            <el-table-column align="left" prop="name" label="姓名" width="100"></el-table-column>
                            <el-table-column align="center" prop="id" label="工号" width="100"></el-table-column>
                            <el-table-column align="left" prop="major" label="专业"></el-table-column>
                            <el-table-column align="center" prop="grade" label="年级" width="100"></el-table-column>
                            <el-table-column align="center" prop="class" label="班级" width="120"></el-table-column>
                            <el-table-column align="center" prop="taskState" label="任务状态" width="100">
                                <template #default="scope">
                                    <span :color="scope.row.taskState">{{ scope.row.taskState }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column align="center" prop="score" label="分数" width="70"></el-table-column>
                            <el-table-column align="center" prop="operation" label="操作" width="100" >
                                <template #default="scope">
                                    <span style="color:#5a8cff;">{{ scope.row.operation }}</span>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                    <!-- 底部分页器 -->
                    <div class="tableFooter">
                        <div class="left">
                            <div class="total">共计: {{ totalSize}} 条</div>
                        </div>
                        <div class="right">
                            <div class="pagination">
                                <el-pagination
                                    layout="prev, pager, next"
                                    :total="totalSize"
                                    :page-size="pageSize"
                                    background
                                    size="small"
                                    @current-change="handleSizeChange"
                                />                        
                            </div>
                            <div class="selector">
                                <el-select 
                                v-model="pageSize" 
                                placeholder="每页条数" 
                                style="width: 80px;" 
                                size="small"
                                @change="getTableData(searchValue);"
                                >
                                    <el-option label="5条/页" :value="5" selected></el-option>
                                    <el-option label="10条/页" :value="10"></el-option>
                                    <el-option label="20条/页" :value="20"></el-option>
                                </el-select>
                            </div>
                            <div class="jump">
                                <span class="title">前往:</span>
                                <input type="text" v-model="pageNum" @change="getTableData(searchValue);">
                            </div>                        
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.bseWorkProceedDetail {
    width: 100%;
    height: 100%;
    .header{
        width: 100%;
        height: 10%;
        padding-left: 15px;
        display: flex;
        align-items: center;
        gap:10px;
        color:#7f7f7f;
        border-top: 1px solid;
        border-bottom: 1px solid;
        span:hover{
            color:#4c5fbc;
            font-weight: 600;
        }
    }
    .layout{
        width: 100%;
        height: 90%;
        padding: 20px 40px;
        .info{
            width: 100%;
            height: 130px;
            padding: 15px 10px;
            background-color: white;
            border-radius: 5px;
            color:#4e5969;
            font-size: 15px;
            .infoHeader{
                width: 100%;
                height: 30px;
                border-bottom: 1px dashed #000;
                font-size: 18px;
                font-weight: 500;
                color:#000;
            }
            .infoContent{
                width: 100%;
                display: flex;
                flex-wrap: wrap;
                .item{
                    margin-top: 10px;
                    width: 33%;
                    display: flex;
                    align-items: center;
                    .title{
                        margin-right: 10px;
                    }
                }
                .score{
                    margin-top: 10px;
                    width: 100%;
                    display: flex;
                    align-items: center;
                    .title{
                        width: 70px;
                    }
                    .input{
                        margin-right: 30px;
                        &:focus-within{
                            border-radius: 10px;
                            outline: 1px solid #165dff;
                        }
                        input{
                            height: 30px;
                            width: 12vw;
                            outline: none;
                            border: none;
                            border-radius: 10px;
                            background-color: #f2f3f5;
                            text-indent: 10px;
                        }
                    }
                    .save{
                        width: 5vw;
                        height: 30px;
                        border-radius: 3px;
                        background-color: #165dff;
                        text-align: center;
                        line-height: 30px;
                        color:white;
                        cursor: pointer;
                        &:hover{
                            background-color: #165cffd7;
                        }
                    }
                }
            }
        }
        .dataTable {
            width: 100%;
            height: calc(100% - 150px);
            margin-top: 20px;
            .content{
                width: 100%;
                height: 100%;                    
                padding: 0 15px;
                background-color: #ffffff;
                border-radius: 10px;
                .tableHeader{
                    width: 100%;
                    height: 15%;
                    display: flex;
                    justify-content: space-between;
                    border-bottom: 1px solid #e5e6eb;
                    font-weight: 600;
                    color:#000;
                    .left {
                        width: 250px;
                        height: 100%;
                        padding-bottom: 10px;
                        display: flex;
                        align-items: flex-end;
                        font-size: 20px;
                    }
                    .right {
                        width: calc(100% - 250px);
                        height: 100%;
                        padding-bottom: 10px;
                        display: flex;
                        align-items: flex-end;
                        justify-content: flex-end;                  
                        .search {
                            width: 20vw;
                            height: 4vh;
                            display: flex;
                            align-items: center;
                            border-radius: 6px;
                            background-color: #f1f2f3;
                            transition: transform 0.2s ease-in-out; 
                            &:hover{
                                background-color: #e0e1e2;
                            }
                            input{
                                height: 100%;
                                width: 90%;
                                outline: none;
                                border: none;
                                background-color: transparent;
                                text-indent: 1em;
                            }
                            .icon{
                                width: 10%;
                                height: 100%;
                                display: flex;
                                align-items: center;
                                justify-content: center;
                            }
                        }
                    }
                    .searchActive {
                        transform: translateX(-20vw) scale(1.1);
                        width: 20vw;
                        border: 2px solid #4c5fbc;
                        background-color: #ffffff!important;
                    }
                }
                .tableContent{
                    width: 100%;
                    height: 70%;
                    font-weight: 500;
                    [color="未提交"]{
                        color: #898989;
                    }
                    [color="审核通过"]{
                        color: #4bc65f;
                    }
                    [color="未审核"]{
                        color: #ff0000;
                    }
                }
                .tableFooter {
                        width: 100%;
                        height: 10%;
                        padding: 0 15px;
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        .left{
                            font-size: 12px;
                        }
                        .right{
                            display: flex;
                            gap:15px;
                            .jump{
                                .title{
                                    margin-right: 5px;
                                    font-size: 12px;
                                }
                                input{
                                    width: 25px;
                                    height: 25px;
                                    text-align: center;
                                    line-height: 25px;
                                    border: none;
                                    outline: none;
                                    border-radius: 5px;
                                    background-color: #f2f3f5;
                                    color:#86909c;
                                    &:focus{
                                        border: 1px solid #165dff;
                                    }
                                }
                            }
                        }
                }
            }
        }
    }
}
</style>